package service.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import dao.EmployeeDao;
import model.Employee;
import service.EmployeeService;


public class EmployeeServiceImpl implements EmployeeService{
	
//调用dao层的对象EmployeeDao
	private EmployeeDao employeeDao=new EmployeeDao();
	
	@Override
	public int login(String username, String password) {
		// TODO 自动生成的方法存根
		int loginFlag=0;
		List params=new ArrayList<>();
		params.add(username);
		params.add(password);
		//定义判断登录的查询语句
		String sql="SELECT * from employee where username=? and `password`=?";
		//调用dao层对象的select方法
		try {
			if(employeeDao.selectByUsername(sql, params).next())
				loginFlag=1;
			return loginFlag;
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return loginFlag;
	}
	@Override
	public int register(Employee employee) {
		// TODO 自动生成的方法存根
		return employeeDao.insert(employee);
	}
}
